#include <stdio.h>
#include <unistd.h>

int main(){
    char* args[]={
        "ls",
        "-a",
        "-l",
        NULL
    };
    pid_t id = fork();
    if(id < 0){printf("进程创建失败\n");return 1;}
    if(id == 0){
        sleep(2);
        printf("程序替换开始！\n");
        //execv("/usr/bin/ls", args);
        //execlp("ls", "ls", "-a", "-l", NULL);
        //execvp("ls", args);
        execl("./OtherExe", "OtherExe", "-a", "-l", "b", NULL);
        printf("子进程替换成ls程序成功\n");
    }else{
        printf("父进程等待子进程中\n");
        waitpid(id, NULL, 0);
        printf("等待子进程成功\n");
        sleep(2);
        printf("父进程执行结束\n");
    }

    return 0;
}
